package com.example.contrl;

import com.example.pojo.ParseStudent;
import com.example.pojo.PostSelect;
import com.example.pojo.Result;
import com.example.service.StudentService;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.support.lob.LobHandler;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Vector;

@Slf4j
@RestController
public class StudentContrl {
    @Autowired
    private StudentService studentService;

    /*
    * 学生注册
    * */
    @PostMapping("/register")
    public Result Register(@RequestBody Map<String,String> map){
        log.info("学生注册：{},{},{},{}",map.get("id"),map.get("name"),map.get("passwd"),map.get("CLASS"));
        studentService.add(map.get("id"),map.get("name"),map.get("passwd"),map.get("CLASS"));
        return Result.success();
    }


    /*
    * 查询学生
    * */
    @PostMapping ("/student")
    public Result student(){
        log.info("查询学生");
        Vector<ParseStudent> students=studentService.select();
        return Result.success(students);
    }

    /*
    * 条件查询学生
    * */
    @GetMapping ("/select")
    public Result  selectStudent( String id, String aaClass ,String teacher,String name){
        log.info("查询学生{}，{},{},{}",id,aaClass,teacher,name);
        Vector<ParseStudent> students=studentService.selectStudent(id,aaClass,teacher,name);
        return Result.success(students);
    }



    /*
    * 修改学生
    * */
    @PostMapping("/student/update")
    public Result updateStudent(@RequestBody ParseStudent parseStudent){
        log.info("修改{}",parseStudent);
       studentService.update(parseStudent);
        return Result.success();
    }

    /*
    * 删除学生
    * */
    @GetMapping("/student/delete/{id}")
    public Result deleteStudent(@PathVariable String id){
        log.info("删除学生{}",id);
        studentService.delete(id);
        return Result.success();
    }

    /*
    * 添加课程
    * */
    @GetMapping("student/{sid}/{cid}/{course}/{name}")
    public Result StudentCourse(@PathVariable String sid,@PathVariable String cid,@PathVariable String course,@PathVariable String name){
        log.info("{}选择课程{}",name,course);
        studentService.studentCourse(sid,cid,course, name);
        return Result.success();
    }



}
